﻿using System;
using System.IO;
using System.Configuration;

namespace SBPweb.Forge.Logger.Writers
{

    public class FileLogWriterStreamFactory : LogWriterStreamFactory
    {

        public override Stream InstantiateStreamBasedOnSettings(KeyValueConfigurationCollection settings)
        {
            string fileName = ".\\" + AppDomain.CurrentDomain.FriendlyName + ".log";
            FileAccess fileAccess = FileAccess.Write;
            FileMode fileMode = FileMode.Append;
            if (settings["fileName"] != null)
            {
                fileName = settings["fileName"].Value;
            }
            if (settings["fileMode"] != null)
            {
                fileMode = (FileMode)Enum.Parse(typeof(FileMode), settings["fileMode"].Value);
            }
            if (settings["fileAccess"] != null)
            {
                fileAccess = (FileAccess)Enum.Parse(typeof(FileAccess), settings["fileAccess"].Value);
            }
            Stream stream = new FileStream(fileName, fileMode, fileAccess);
            return stream;
        }

    }

}